import {Component, OnInit} from '@angular/core';

import {HttpService} from '@kylin/http';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
    templateUrl: './swagger.component.html',
    styleUrls: ['./swagger.component.css']
})
export class SwaggerComponent implements OnInit {

    swaggerList = [];

    constructor(private http: HttpService,
                private nzMessageService: NzMessageService) {
    }

    ngOnInit() {
        this.fetchSwaggerList();
    }

    fetchSwaggerList() {
        this.http.get('/swaggerList')
            .then(res => {
                if (res.resp_code === '10000' && res.data.length > 0) {
                    this.swaggerList = res.data.map(value => {
                        value.url = encodeURIComponent(value.url);
                        return value;
                    });
                } else {
                    this.nzMessageService.error(res.resp_msg);
                }
            })
            .catch(err => {
                this.nzMessageService.error('获取SwaggerList失败,请检查网络')
            })
    }

}
